'''
飞享e生升级版
'''
import sys

sys.path.append('../')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
from common.helper import Helper
from urllib.parse import urlencode
import requests
import json


class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "飞享e生升级版"

    # 生成产品数据
    def genProductInfo(self):

        plan = {
            "planA":{
                "人身意外伤害-身故、残疾(附加恐怖活动条款)":"10w",
                "火车（含地铁、轻轨）意外伤害身故、残疾":"20w",
                "航空意外伤害身故、残疾":"100w",
                "航班延误（B款）":"180元",
                "意外医疗费用补偿":"3000元",
                "紧急医疗运送和送返":"10w",
                "家庭财产损失":"2w",
                "个人物品损失":"5000元"

            },
            "planB": {
                "人身意外伤害-身故、残疾(附加恐怖活动条款)": "20w",
                "火车（含地铁、轻轨）意外伤害身故、残疾": "50w",
                "航空意外伤害身故、残疾": "150w",
                "航班延误（B款）": "180元",
                "紧急医疗运送和送返": "10w",
                "家庭财产损失": "2w",
                "个人物品损失": "5000元",
                "一般医疗保险金":"30w"
            }
        }

        prices = ["79","299"]

        expire = "1"

        for value,key in zip(plan.values(),prices):

            value = "'" + json.dumps( value ,ensure_ascii=False) + "'"

            self.mysql.cursor.execute(

                'INSERT INTO `飞享e生升级版`(`plan`,`expire`,`price`)VALUES({0},"{1}","{2}")'.format( value,str(expire),Helper.decimalParse(key))


            )
            self.mysql._conn.commit()



if __name__ == '__main__':
    s = Spider()

    s.genProductInfo()
